import { Catch, HttpStatus } from '@midwayjs/core'
import { Context } from '@midwayjs/koa'

@Catch()
export class DefaultErrorFilter {
  async catch(err: Error, ctx: Context) {
    // @ts-ignore
    const status = err.status ?? HttpStatus.INTERNAL_SERVER_ERROR

    ctx.status = status

    return {
      status,
      message: err.message
    }
  }
}
